﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Threading;
using Sparrow;

namespace Sparrow.Globalization
{
    
    public static class LocalizableActions
    {
        public static string Localizable(this string source)
        {
            return source.Localizable(string.Empty,Thread.CurrentThread.CurrentCulture);  
        }

        public static string Localizable(this string source, CultureInfo culture)
        {
            return source.Localizable(string.Empty, culture);
        }
  
        public static string Localizable(this string source, string category)
        {
            return source.Localizable(category, Thread.CurrentThread.CurrentCulture);
        }

        public static string Localizable(this string source, string category, CultureInfo culture)
        { 
            //if (string.IsNullOrWhiteSpace(source))
            //{
            //    return string.Empty;
            //}

            //var provider = Factory.Provider;

            //var element = provider.Elements
            //    .Where(i=>i.Name == source && i.Category == category && i.Culture == culture)
            //    .FirstOrDefault();

            //if(element == null)
            //{
            //    element = new Element
            //    {
            //        Name = source,
            //        Category = category,
            //        Culture = culture.Name,
            //        Value = source
            //    };

            //    provider.Add(element);
            //}

            //return element.Value;
            return source;
        }

        public static Element Map(this string source, string name)
        {
            return source.Map(name, "", Thread.CurrentThread.CurrentCulture);
        }

        public static Element Map(this string source, string name, CultureInfo culture)
        {
            return source.Map(name, "", culture);
        }

        public static Element Map(this string source, string name, string category)
        {
            return source.Map(name, category, Thread.CurrentThread.CurrentCulture);
        }

        public static Element Map(this string source, string name, string category, CultureInfo culture)
        {
            //var provider = Factory.Provider;

            //var element = provider.Elements
            //    .Where(i => i.Name == name && i.Category == category && i.Culture == culture.Name)
            //    .FirstOrDefault();

            //if (element == null)
            //{
            //    element = new Element
            //    {
            //        Name = name,
            //        Category = category,
            //        Culture = culture.Name,
            //        Value = source
            //    };
                
            //    provider.Add(element);
            //}

            //return element;     
            return null;
        }

        public static string Localizable(this Element element)
        {
            if (element == null)
            {
                return string.Empty;
            }

            return element.Value;
        }
    }

      
}
